﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../../common/jsp/taglibs.jsp"%>
<!-- 
    Copyright (C)  2011  chen wei hua.
    Permission is granted to copy, distribute and/or modify this document
    under the terms of the GNU Free Documentation License, Version 2.0
    or any later version published by the Free Software Foundation;
    with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
    A copy of the license is included in the section entitled "GNU Free Documentation License".
 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>采购管理-新建收货单</TITLE>
<META content="text/html; charset=utf-8" http-equiv=Content-Type>
<%@ include file="../../common/jsp/config.jsp"%>
<%@ include file="../../common/jsp/validate.jsp"%>
<script type="text/javascript" src="common/js/calendar/WdatePicker.js" ></script>
<script type="text/javascript">
var rowIndex = <s:property value="order.orderDetails.size"/> - 1;
function computerTotleAmount() {
	var totleNumber = 0;
	for (var i = 0; i < rowIndex + 1; i++) {
		var amount = $("#materialsAmounts-" + i);
		if (amount.length > 0) {
			totleNumber += parseFloat(amount.val());
		}
	}
	$("#order_totleAmount").val(totleNumber.toFixed(2));
}

function computerAmount(id) {
	var number = $("#materialsNums-" + id).val();
	var prices = $("#materialsPrices-" + id).html();
	var totleValue = number * prices;
	$("#materialsAmounts-" + id).val(totleValue.toFixed(2));
	computerTotleAmount();
}

function saveSubmit() {
	var isError = false;
	$("input[id^='materialsNums-']").each(function(i){
		if (isError) {
			return;
		}
		var id = this.id;
		var planId = id.replace("materialsNums-", "planMaterialsNums-");
		var receivedNumberId = id.replace("materialsNums-", "receiveNumbers-");
		var receiveValue = parseFloat($("#" + receivedNumberId).html()) + parseFloat($(this).val());
		var planValue = parseFloat($("#" + planId).html());
		if (receiveValue >= planValue * 1.05) {
			isError = true;
		}
	});

	if (isError) {
		alert("收货数量超过采购数量的5%，不能保存");
		return false;
	}
	return true;
}

function deleteRow(button) {
	$(button).parents("tr").remove();
	computerTotleAmount();
}

$(document).ready(function() {
	$.validator.setDefaults({
		submitHandler: function(validator, form) {
			var result = saveSubmit();
			if (result) {
				form.submit();
			}
			return false;
		}
	});
	$("#saveMaterialsReceiveOrder").validate();
});
</script>
</HEAD>
<BODY>
    <s:form action="saveMaterialsReceiveOrder">
    <s:hidden name="orderId" value="%{order.id}" />
    <div class="subnav" align="left">
           <table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td width="100%" align="left" height="31">&nbsp;<img src="common/images/title-pk.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt1">采购管理</span>
			&nbsp;<img src="common/images/leftico2.gif" border="0"  align="absmiddle"/>&nbsp;<span class="subnavtxt2">新建收货单</span></td>
		  </tr>
		</table>
      </div>
     <div class="main_1">
       <table width="99%" border="0" cellpadding="10" cellspacing="1" bgcolor="#D3DEEF">
         <tr>
           <td align="left" class="Blue14" bgcolor="#FAFAFA" colspan="4">收货单信息</td>
         </tr>
		<tr>
	      <td width="20%" bgcolor="#FAFAFA" align="right"><strong>供应商名称</strong></td>
	      <td width="30%" bgcolor="#FAFAFA"><s:property value="order.supplierName"/></td>
	      <td width="20%" bgcolor="#FAFAFA" align="right"><strong>对方合同号</strong></td>
	      <td width="30%" bgcolor="#FAFAFA"><s:property value="order.contractNo"/></td>
		</tr>
        <tr>
		    <td bgcolor="#FAFAFA" align="right"><strong>下单日期</strong></td>
		    <td bgcolor="#FAFAFA"><s:date name="order.createDate" format="yyyy-MM-dd"/></td>
		    <td bgcolor="#FAFAFA" align="right"><strong>要求到货日期</strong></td>
		    <td bgcolor="#FAFAFA"><s:date name="order.exceptArriveDate" format="yyyy-MM-dd"/></td>
		 </tr>
         <tr>
		    <td bgcolor="#FAFAFA" align="right"><strong>预计到货日期</strong></td>
		    <td bgcolor="#FAFAFA">
		      <s:textfield name="order.arriveDate" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})" size="10" readonly="true" cssClass="{required:true}"/>
		      <span class="red-text1">*</span>
		    </td>
		    <td bgcolor="#FAFAFA" align="right"><strong>总金额</strong></td>
		    <td bgcolor="#FAFAFA">
				<s:textfield id="order_totleAmount" name="order.totleAmount" readonly="true" size="10" cssClass="inputdisabled"/>
			</td>
		 </tr>
       </table>
     </div>
     <div class="clear"></div>
	 <div class="main_scroll">
       <table width="1300px" cellpadding="0" cellspacing="1" border="0" class="ksglxx2a" id="materialsList">
        <tr class="ksglxx2bg">
          <th width="50px" >大分类</th>
          <th width="60px" >中分类</th>
          <th width="95px" >名称</th>
          <th width="180px" >型号</th>
          <th width="180px" >其他</th>
		  <th width="50px">单位</th>
		  <th width="95px">生产批号</th>
		  <th width="65px">采购数量</th>
		  <th width="60px">已收货数</th>
		  <th width="65px">到货数量</th>
		  <th width="65px">价格</th>
		  <th width="95px">金额</th>
		  <th width="125px">备注</th>
		  <th>&nbsp;</th>
		</tr>
	    <s:iterator value="order.orderDetails" id="detail" status="st">
          <s:if test="#st.Odd">
            <tr class="odd">
          </s:if>
          <s:else>
            <tr class="even">
          </s:else>
          <td><s:property value="#detail.materialsRootCategory" />
              <s:hidden name="rootCategorys" value="%{#detail.materialsRootCategory}" />
          </td>
          <td><s:property value="#detail.materialsCategory" />
              <s:hidden name="categorys" value="%{#detail.materialsCategory}" />
          </td>
          <td><s:property value="#detail.materialsName" /></td>
          <td><s:property value="#detail.materialsType" /></td>
          <td><s:property value="#detail.materialsSku" />
          	  <s:hidden name="materialsSkus" value="%{#detail.materialsSku}" /></td>
          <td><s:property value="#detail.unit" /></td>
          <td><s:property value="#detail.planNo" />
              <s:hidden name="planNos" value="%{#detail.planNo}" /></td>
          <td><span id='planMaterialsNums-<s:property value="#st.index" />'><s:property value="#detail.number" /></span></td>
          <td><span id='receiveNumbers-<s:property value="#st.index" />'><s:property value="#detail.receiveNumber" /></span></td>
          <td>
    		<s:textfield id='materialsNums-%{#st.index}' name="materialsNums" size="5" 
					cssClass="{required:true,maxlength:10,number:true}" onblur="computerAmount(%{#st.index})" value="%{#detail.number-#detail.receiveNumber}" />
	      </td>
		  <td><span id='materialsPrices-<s:property value="#st.index" />'>
		      <s:property value="#detail.price" /></span>
		      <s:hidden name="materialsPrices" value="%{#detail.price}" />
		  </td>
		  <td><s:textfield id='materialsAmounts-%{#st.index}' name="materialsAmounts" readonly="true" size="10" value="%{#detail.amount}" cssClass="inputdisabled"/></td>
          <td><s:property value="#detail.remark" />
              <s:hidden name="remarks" value="%{#detail.remark}" /></td>
          <td><s:hidden name="detailIds" value="%{#detail.id}" />
              <s:hidden name="materialsNos" value="%{#detail.materialsNo}" />
		      <s:hidden name="materialsIds" value="%{#detail.materialsId}" />
            <input type="button" value="删除" class="input1" onclick='deleteRow(this)' />
          </td>
	    </tr>
	    </s:iterator>
       </table>
      </div>
     <div class="clear"></div>
	 <div class="main_1">
		<table width="98%" border="0" cellpadding="5" cellspacing="0" class="gr-text1">
		   <tr>
			 <td width="45%" align="right">
			   <s:submit value="保存" cssClass="input1" />&nbsp;&nbsp;&nbsp;&nbsp;
			   <input type="button" value="关闭" class="input1" onclick='javascript:window.location.href="supplierOrderList.action"' /></td>
			 <td width="55%" align="left"></td>
		   </tr>
	   </table>
	</div>
	<div class="clear"></div>
	</s:form>
</BODY></HTML>
